//
//  RVTabBarController.m
//  RememberVocabularies
//
//  Created by 伍银荣 on 2017/10/11.
//  Copyright © 2017年 WYR. All rights reserved.
//

#import "RVTabBarController.h"
#import "RVHomeViewController.h"
#import "RVTranslateViewController.h"
#import "RVMyViewController.h"
#import "RVNavigationController.h"

@interface RVTabBarController ()


@end

@implementation RVTabBarController

//设置tabBar主题
+(void)initialize
{
    //设置默认字体
    NSMutableDictionary *dict1 = [NSMutableDictionary dictionary];
    dict1[NSFontAttributeName] = [UIFont systemFontOfSize:12];
    dict1[NSForegroundColorAttributeName] = [UIColor grayColor];
    
    //设置选中字体
    NSMutableDictionary *dict2 = [NSMutableDictionary dictionary];
    dict2[NSFontAttributeName] = [UIFont systemFontOfSize:12];
    dict2[NSForegroundColorAttributeName] = MRGlobalBg;
    
    //设置tabBar按钮文字
    UITabBarItem *item = [UITabBarItem appearance];
    [item setTitleTextAttributes:dict1 forState:UIControlStateNormal];
    [item setTitleTextAttributes:dict2 forState:UIControlStateSelected];
}

- (void)viewDidLoad {
    [super viewDidLoad];
    //首页
    //添加一个子视图控制器
    [self addChildViewController:[RVHomeViewController new] imageName:@"TabBar_home_23x23_" selectedImage:@"TabBar_home_selected_23x23_" title:@"首页"];
    //翻译
    [self addChildViewController:[RVTranslateViewController new]imageName:@"RVTabBar_translate" selectedImage:@"RVTabBar_translate_selected" title:@"翻译"];
    //我的
    [self addChildViewController:[RVMyViewController new] imageName:@"TabBar_me_boy_23x23_" selectedImage:@"TabBar_me_boy_selected_23x23_" title:@"我的"];
}

//给tabbar添加子视图控制器方法
//子视图控制器、默认tab图片、点击后图片、文字
-(void)addChildViewController:(UIViewController *)childController imageName:(NSString *)imageName selectedImage:(NSString *)selectedImageName title:(NSString *)title
{
    UITabBarItem *item = [[UITabBarItem alloc]initWithTitle:title image:[UIImage imageNamed:imageName] selectedImage:[[UIImage imageNamed:selectedImageName] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal]];
    childController.tabBarItem = item;
    //包装一个导航栏控制器，添加导航条为tab子控制器
    RVNavigationController  *nav = [[RVNavigationController alloc]initWithRootViewController:childController];
    //设置视图的导航栏标题
    childController.navigationItem.title = title;

    [self addChildViewController:nav];
}



- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
